package com.e3mall.service.impl;

import com.e3mall.interfaces.TbItemService;
import com.e3mall.manage.mapper.TbItemMapper;
import com.e3mall.manage.pojo.TbItem;
import com.e3mall.manage.pojo.TbItemExample;
import com.e3mall.utils.DataGridPageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @作者: Vgger
 * @E-Mail:1055106789@qq.com
 * @描述:
 * @修改时间: Created in 21:45 2018/4/21
 */
@Service
public class TbItemServiceImpl implements TbItemService {

    //  注入mapper
    @Autowired
    private TbItemMapper itemMapper;

    @Override
    public TbItem getItemById(Long itemId) {
        return itemMapper.selectByPrimaryKey(itemId);
    }

    /**
     *
     * @param page
     * @param rows
     * @return
     */
    @Override
    public DataGridPageResult getPage(Integer page, Integer rows) {
//      调用PageHelper方法,该方法会自动对该方法下第一条查询语句进行拦截并且添加分页条件
        PageHelper.startPage(page, rows);
        TbItemExample example = new TbItemExample();
        Page itemList = (Page) itemMapper.selectByExample(example);
        DataGridPageResult result = new DataGridPageResult();
        result.setRows(itemList.getResult());
        result.setTotal(itemList.getTotal());
        return result;
    }
}
